package controllers;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import data.AutoSiteData;
import data.BlogData;

import models.AutoSite;
import models.Blog;

public class AddSiteServlet extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
		throws IOException {
		String blogId = (String) request.getParameter("blogId");
		ArrayList<AutoSite> sites = AutoSiteData.getByBlogId(blogId);
		Blog blog = BlogData.getById(blogId);
		
		request.setAttribute("blog", blog);
		request.setAttribute("sites", sites);
		try {
            request.getRequestDispatcher("/pages/add_site.jsp").forward(request, response);
        } catch (Exception e) {
            //TODO: handle exception
            e.printStackTrace();
        }
	}
	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
		throws IOException {
		String blogId = (String) request.getParameter("blogId");
		ArrayList<AutoSite> sites = AutoSiteData.getByBlogId(blogId);
		Blog blog = BlogData.getById(blogId);
		
		request.setAttribute("blog", blog);
		request.setAttribute("sites", sites);
		try {
            request.getRequestDispatcher("/pages/add_site.jsp").forward(request, response);
        } catch (Exception e) {
            //TODO: handle exception
            e.printStackTrace();
        }
	}
}